// js/ui.js
import { gameState } from './state.js';
import { Player } from './player.js';
import { Enemy } from './enemy.js';

// 初始化UI
export function setupUI() {
    gameState.addListener(updateDisplay);
    setInterval(updateDisplay, 100);
}

export function updateDisplay() {
    // 更新金币显示
    document.getElementById('gold').textContent = gameState.gold;
    
    // 更新玩家状态
    document.getElementById('playerAttack').textContent = Player.attack;
    document.getElementById('playerHealth').style.width = 
        (Player.currentHealth / Player.maxHealth * 100) + '%';
    
    // 更新敌人状态
    document.getElementById('enemyLevel').textContent = Enemy.level;
    document.getElementById('enemiesRemaining').textContent = Enemy.remaining;
    document.getElementById('enemyHealth').style.width = 
        (Enemy.currentHealth / Enemy.maxHealth * 100) + '%';
    
    // 更新商店按钮
    document.getElementById('attackCost').textContent = window.Shop.attackCost;
    document.getElementById('healCost').textContent = window.Shop.healCost;
    document.getElementById('attackBtn').disabled = gameState.gold < window.Shop.attackCost;
    document.getElementById('healBtn').disabled = gameState.gold < window.Shop.healCost;
}

export function addCombatLog(text) {
    const log = document.getElementById('combatLog');
    log.innerHTML += `<div>${text}</div>`;
    log.scrollTop = log.scrollHeight;
}